/*
 * @lc app=leetcode.cn id=202 lang=javascript
 *
 * [202] 快乐数
 */

// @lc code=start
/**
 * @param {number} n
 * @return {boolean}
 */
 function getNext(num) {
    let sum = 0;
    while(num > 0) {
        const d = num % 10;
        sum += d*d;
        num = Math.floor(num / 10);
    }
    return sum;

}
var isHappy = function(n) {
  // 快慢指针
  let slow = n;
  let fast = getNext(n);
  while(slow !== fast && fast !== 1) {
      slow = getNext(slow);
      fast = getNext(getNext(fast));
  }
  return fast === 1;
};
// @lc code=end

